package com.mall4j.cloud.product.service.impl;

import com.mall4j.cloud.product.model.BrowseHistory;
import com.mall4j.cloud.product.model.Spu;
import com.mall4j.cloud.product.model.SpuHistory;
import com.mall4j.cloud.product.repository.BrowseHistoryRepository;
import com.mall4j.cloud.product.repository.SpuRepository;
import com.mall4j.cloud.product.service.BrowseHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class BrowseHistoryServiceImpl implements BrowseHistoryService {
    @Autowired
    private BrowseHistoryRepository browseHistoryRepository;

    @Autowired
    private SpuRepository spuRepository;

    @Override
    public void addBrowseHistory(Long userId, Long spuId) {
        BrowseHistory history = new BrowseHistory();
        history.setUserId(userId);
        history.setSpuId(spuId);
        history.setBrowseTime(new Date());
        browseHistoryRepository.save(history);
    }
    @Override
    public List<SpuHistory> getBrowseHistoryList(Long userId) {
        return spuRepository.findSpuHistory(userId);
    }

    @Override
    public void deleteHistory(){
        browseHistoryRepository.deleteHistory();
    }

}
